package week_home_work02;

import java.util.Scanner;

/**
 * @author zdl
 * @date 2024/11/23
 */
public class Demo53 {
    public static void main(String[] args) {
        //设计一个程序，计算1到n之间的所有合数之和。
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个正整数:");
        int num = sc.nextInt();
        int sum = 0;
        for (int i = 2; i <= num; i++) {
            for (int j = 2; j < Math.sqrt(i); j++) {
                if (i % j == 0) {
                    System.out.print(i + "\t");
                    sum += i;
                    break;
                }
            }
        }
        System.out.println();
        System.out.println("1到" + num + "之间的所有合数之和:" + sum);
    }
}
